package com.huan.quartz.common;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * quartz job 的状态
 *
 * @author huan.fu
 * @date 2018/9/10 - 16:52
 */
@AllArgsConstructor
@Getter
public enum JobStatus {

	/**
	 * 启用 job
	 */
	START("1", "启用"),

	/**
	 * 禁用 job
	 */
	DISABLED("0", "启用");

	private String code;
	private String desc;

	public static JobStatus from(String jobStatus) {
		return Arrays.stream(JobStatus.values()).filter(job -> Objects.equals(job.getCode(), jobStatus)).findFirst().orElse(JobStatus.DISABLED);
	}

	/**
	 * job 是否启用
	 *
	 * @param jobStatus
	 * @return
	 */
	public static boolean isStart(String jobStatus) {
		return Objects.equals(START, from(jobStatus));
	}

	/**
	 * job 是否禁用
	 *
	 * @param jobStatus
	 * @return
	 */
	public static boolean isDisables(String jobStatus) {
		return Objects.equals(DISABLED, from(jobStatus));
	}

}
